package com.xujianjie.orderservice.mapper;

import com.xujianjie.orderservice.model.Order;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrderMapper
{
    @Insert("insert into user_order(user_id, goods_id, user_name, goods_name, goods_count, price, total_price) values(" +
            "#{order.userId}, " +
            "#{order.goodsId}, " +
            "#{order.userName}, " +
            "#{order.goodsName}, " +
            "#{order.goodsCount}, " +
            "#{order.price}, " +
            "#{order.totalPrice}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(@Param("order") Order order);

    @Select("select * from order where id = #{id}")
    Order findById(@Param("id") int id);
}